<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${name_china}-导入</title>
<%@include file="/common/headmy.jsp"%>
<link
	href="<%=request.getContextPath()%>/static/plugin/uploadify/style/uploadify.css"
	rel="stylesheet">
<script
	src="<%=request.getContextPath()%>/static/plugin/uploadify/js/jquery.uploadify.js"></script>
<style>
    .align-right {
	    font-size: 14px;
	    text-align: right !important;
     }
     .imp {
	    font-size: 14px;
	    text-align: right !important;
	    color:blue;
     }
</style> 
</head>
<body class="iframe-page">
	<div class="page-title-wrapper">
		<div class="page-title">
			<div class="page-title-text">
				<span>导入${name_china}</span> <span class="split"></span> 
			</div>
			<a id="goBack" class="btn-return distance-left" href="javascript:;"><i
				class="icon icon-arrow-left"></i>返回上级</a>
		</div>
		<div class="page-title-border"></div>
	</div>
	<div class="grid-layout" style="padding: 10px;">
		<form id="form" method="post">
			<div class="grid-row distance-double">
				<div class="col-1 align-right">
					<span class="field-required">*</span>上传附件
				</div>
				<div class="col-5">
					<input id="fileUpload" name="fileUpload" type="text" class="summer-input distance-right" data-validatebox="validType:['required']"> 
					<label class="label-secondary "></label> 
					<input type="hidden" id="id" name="id">
				</div>
			</div>
			<div class="grid-row distance-double">
				<div class="col-1 align-right">
					<p class="summer-grid-title">
						<span class="field-required">*</span>导入提示
					</p>
				</div>
				<div class="col-5">
					<a class="imp" href="<%=request.getContextPath()%>/static/template/excelImport/demo/templet/templet.xls"> 模板下载</a>
				</div>
			</div>
			
			
		</form>
	</div>
	<div class="grid-row distance-double">
		<div class="form-btn-wrapper" id="funcbar">
			<a class="btn btn-normal" id="backBtn">关闭</a>
		</div>
		
	</div>

	<script>
		var permission = CommonUtil.getPermission('${name_english}');
		var CONST_URL = {
			INIT_MAIN: basePath + '${common_url}init',
			IMP : basePath + '${common_url}imp'
		};
		$(function() {
			//初始化保存按钮和保存并继续按钮
			$('#funcbar').prepend($.funcbar({
				type : 'button',
				data : permission,
				permit : [ '${name_english}:imp' ]
			}));
			createConfig();
			//保存按钮
			$('#funcbar').on('click', 'a[data-permit="${name_english}:imp"]', {
				isContinue : false
			}, submit);
			
			$(function() {
				$('#goBack,#backBtn').on('click', backMain);
			});
			
		});
		function submit() {
			
			var fileId = $('#form').find('input[name=fileId]').val();
			if ( fileId == ''|| fileId == null ) {
				showTip("请选择EXCEL文件上传","danger");
				return false;
			}
			$("#form").form(
					{
						buttons : [ '#saveBtn' ],
						onSubmitSuccess : function(data) {
							if (data.result) {
								if (data.result == "ERROR") {
									window.location.href = basePath
											+ "/imp/ExcelError/init?backHome="
											+ CONST_URL.INIT_MAIN;//此页面为公共页面，backHome须手动更改
								} else if (data.result == "success") {
									showTip("导入成功","ok");
									setTimeout(function() {								
										backMain();
									}, 2000);
								} else {
									showTip("服务器繁忙，请销后重试！","danger");
								}
							}
						},
						ajax : {
							url : CONST_URL.IMP
						}
					}).form("submit");
		}
		//上传初始化方法
		function createConfig() {
			var config = {
				"sessionId" : '${pageContext.session.id}',
				"formId" : "form",
				"items" : [ {
					'id' : "fileUpload",// 按钮id
					'fileSizeLimit' : '10240KB',// 文件大小
					'multi' : false, // 是否多选
					'required' : true, // 是否必填
					'fileTypeExts' : '**.xls',
					'uploadLimit' : 1,// 上传队列最大个数
					'tableName' : "T_DEMO_TEMPLET",// 表名
					'field' : 'FILE_ID',// 数据库字段标识
					'queueSizeLimit' : 1,// 每次选择文件数量
					'hiddenFileIds' : "fileId"// 存储文件id隐藏框的name，程序自动创建
				} ]
			};
			upLoadUtil.initUplod(config);// 初始化上传插件
		}
		
		//警告消息
		function showTip(msg,type) {
			$.stip({
				type : type,//显示类型 有info、 ok、 danger
				top : '20px', //显示的X坐标,相对父元素进行决定定位
				left : '50%',
				text : msg, //显示的tip字符，也可以是html字符串
				//'min-width' : '300',//自适应
				autoHide : 2000, //2000ms , 0表示 立即隐藏 ， false 表示不进行隐藏
				beforeShow : function() {
					
				},
				beforeHide : function() {
					if("ok"==type){
						window.location.href = CONST_URL.INIT_MAIN;
					}
				}
			});
		}
		
		//返回主页面
		function backMain() {
			window.location.href = CONST_URL.INIT_MAIN;
		}
	</script>
</body>
</html>